package View;

import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.xml.soap.SAAJResult;
import javax.swing.JTable;
import javax.swing.JButton;

import javax.swing.JPanel;
import javax.swing.JRadioButton;

import java.awt.Font;
import java.awt.event.ActionEvent;
//import javax.swing.Action;
//import javax.swing.AbstractAction;
//import javax.swing.JCheckBoxMenuItem;
//import java.awt.Choice;

public class PatternConfigView extends JFrame {
	
	JLabel ProductSelect;
	JLabel AgeRange;
	JLabel SelectCity;
	JLabel CustomerImportance;
	JLabel CustomerInterestingLevel;
	JLabel CustomerPermissionlevel;
	JComboBox ProductSelectField;
	JComboBox SelectCityField;
	JRadioButton FirstAgeField;
	JRadioButton SecondAgeField;
	JRadioButton ThirdAgeField;
	JRadioButton FourthAgeField;
	JComboBox CustomerImportanceField;
	JComboBox CustomerInterestingLevelField;
	JComboBox CustomerPermissionLevelField;
	JButton SubmitButton;
	JButton BackButton;
	JLabel MassageToCustomer;
	JTextField MassageToCustomerField;

	//private final Action action = new SwingAction();
	public PatternConfigView() {
		getContentPane().setLayout(null);
		
		this.setTitle("New Pattern Configuration");
		this.setSize(493,471);
		
		ProductSelect = new JLabel("Select Product");
		ProductSelect.setFont(new Font("Tahoma", Font.BOLD, 12));
		ProductSelect.setBounds(20, 11, 110, 26);
		getContentPane().add(ProductSelect);
		
		AgeRange = new JLabel("Age Range");
		AgeRange.setFont(new Font("Tahoma", Font.BOLD, 12));
		AgeRange.setBounds(20, 48, 84, 26);
		getContentPane().add(AgeRange);
		
		SelectCity = new JLabel("Select City ");
		SelectCity.setFont(new Font("Tahoma", Font.BOLD, 12));
		SelectCity.setBounds(20, 85, 97, 21);
		getContentPane().add(SelectCity);
		
		CustomerImportance = new JLabel("Customer Importance");
		CustomerImportance.setFont(new Font("Tahoma", Font.BOLD, 12));
		CustomerImportance.setBounds(20, 109, 165, 34);
		getContentPane().add(CustomerImportance);
		
		CustomerInterestingLevel = new JLabel("Customer Interesting-Level");
		CustomerInterestingLevel.setFont(new Font("Tahoma", Font.BOLD, 12));
		CustomerInterestingLevel.setBounds(10, 139, 201, 36);
		getContentPane().add(CustomerInterestingLevel);
		
		CustomerPermissionlevel = new JLabel("Customer Permissions Level ");
		CustomerPermissionlevel.setFont(new Font("Tahoma", Font.BOLD, 12));
		CustomerPermissionlevel.setBounds(10, 182, 173, 26);
		getContentPane().add(CustomerPermissionlevel);
		
		MassageToCustomer = new JLabel("Message To Customer");
		MassageToCustomer.setFont(new Font("Tahoma", Font.BOLD, 12));
		MassageToCustomer.setBounds(10, 222, 151, 14);
		getContentPane().add(MassageToCustomer);
		
		ProductSelectField = new JComboBox();
		ProductSelectField.setBounds(196, 15, 145, 20);
		getContentPane().add(ProductSelectField);
		
		SelectCityField = new JComboBox();
		SelectCityField.setBounds(196, 86, 145, 20);
		getContentPane().add(SelectCityField);
		
		FirstAgeField = new JRadioButton("18-25");
		FirstAgeField.setBounds(126, 51, 60, 23);
		getContentPane().add(FirstAgeField);
		
		SecondAgeField = new JRadioButton("26-35");
		SecondAgeField.setBounds(196, 51, 60, 23);
		getContentPane().add(SecondAgeField);
		
		ThirdAgeField = new JRadioButton("36-50");
		ThirdAgeField.setBounds(262, 51, 67, 23);
		getContentPane().add(ThirdAgeField);
		
		FourthAgeField = new JRadioButton("51-100");
		FourthAgeField.setBounds(331, 51, 72, 23);
		getContentPane().add(FourthAgeField);
		
		int x=10;
		String[] CustomerImportanceList = new String[x];
		for(int i=0;i<x;++i)
			CustomerImportanceList[i] = Integer.toString(i+1);
		CustomerImportanceField = new JComboBox(CustomerImportanceList);		
		CustomerImportanceField.setBounds(195, 117, 145, 20);
		CustomerImportanceField.addActionListener(CustomerImportanceField);
		getContentPane().add(CustomerImportanceField);
		
		int y=10;
		String[] CustomerInterestingList = new String[y];
		for(int i=0;i<y;++i)
			CustomerInterestingList[i] = Integer.toString(i+1);
		CustomerInterestingLevelField = new JComboBox(CustomerInterestingList);
		CustomerInterestingLevelField.setBounds(196, 148, 145, 20);
		getContentPane().add(CustomerInterestingLevelField);
		
		int z=10;
		String[] CustomerPermissionList = new String[z];
		for(int i=0;i<z;++i)
			CustomerPermissionList[i] = Integer.toString(i+1);
		CustomerPermissionLevelField = new JComboBox(CustomerPermissionList);
		CustomerPermissionLevelField.setBounds(195, 186, 145, 20);
		getContentPane().add(CustomerPermissionLevelField);
		
		MassageToCustomerField = new JTextField();
		MassageToCustomerField.setBounds(158, 222, 245, 158);
		getContentPane().add(MassageToCustomerField);
		MassageToCustomerField.setColumns(10);
		
		SubmitButton = new JButton("Submit");
		SubmitButton.setFont(new Font("Tahoma", Font.BOLD, 15));
		SubmitButton.setBounds(129, 390, 101, 29);
		getContentPane().add(SubmitButton);
		
		BackButton = new JButton("Back");
		BackButton.setFont(new Font("Tahoma", Font.BOLD, 15));
		BackButton.setBounds(240, 390, 101, 29);
		getContentPane().add(BackButton);
			
	}
	/*private class SwingAction extends AbstractAction {
		public SwingAction() {
			putValue(NAME, "SwingAction");
			putValue(SHORT_DESCRIPTION, "Some short description");
		}
		public void actionPerformed(ActionEvent e) {
		}
	}*/
	
	
	public void PatternConfigListener(ActionListener actionListener){
		SubmitButton.addActionListener(actionListener);
		BackButton.addActionListener(actionListener);
	}
	
	public void showWindow(){
		setVisible(true);
	}
	public void hideWindow(){
		setVisible(false);
	}	
	
	public String getProductName(){
		return ProductSelectField.getSelectedItem().toString();
	}
	public String getCustomerCity(){
		return SelectCityField.getSelectedItem().toString();
	}
	public String getFirstAge(){
		return FirstAgeField.getSelectedIcon().toString();
	}
	public String getSecondAge(){
		return SecondAgeField.getSelectedIcon().toString();
	}
	public String getThirdAge(){
		return ThirdAgeField.getSelectedIcon().toString();
	}
	public String getFourthAge(){
		return FourthAgeField.getSelectedIcon().toString();
	}
	
	public String getCustomerImportance(){
		return (String) CustomerImportanceField.getSelectedItem();
	}

	public String getCustomerInteresting(){
		return (String) CustomerInterestingLevelField.getSelectedItem();
	}

	public String getCustomerPermission(){
		return (String) CustomerPermissionLevelField.getSelectedItem();
	}
	
	public String getMassageToCustomer(){
		return MassageToCustomer.getText();
	}
	public  JButton getSubmitButton() {
		return this.SubmitButton;
	}
	public  JButton getBackButton() {
		return this.BackButton;
	}
	
	public String getAge()
	{
	   if(getFirstAge()!=null)
		   return getFirstAge();
	   if(getSecondAge()!=null)
		   return getSecondAge();
	   if(getThirdAge()!=null)
		   return getThirdAge();
	   if(getFourthAge()!=null)
		   return getFourthAge();
	   return null;
	   
	}
	
	public void clearFields()
	{
		ProductSelectField.setSelectedItem(" ");
		SelectCityField.setSelectedItem(" ");
		CustomerImportanceField.setSelectedItem(" ");
		CustomerInterestingLevelField.setSelectedItem(" ");
		CustomerPermissionLevelField.setSelectedItem(" ");
		MassageToCustomer.setText(" ");
		FirstAgeField.setSelectedIcon(null);
		SecondAgeField.setSelectedIcon(null);
		ThirdAgeField.setSelectedIcon(null);
		FourthAgeField.setSelectedIcon(null);
		
	}
	
	
}